package com.tool.stock.store;

import com.tool.common.datastructure.CircleIntQueue;
import lombok.Getter;

/**
 * 保存五日均线.
 */
public class FiveAverageStore {

    /**
     * 使用循环队列保存数据.
     */
    private CircleIntQueue circleIntQueue;

    private FiveAverageStore() {

        circleIntQueue = new CircleIntQueue(5);
    }

    @Getter
    private static FiveAverageStore instance = new FiveAverageStore();

    /**
     * 添加一个价格.
     *
     * @param price 股价
     */
    public FiveAverageStore addPrice(int price) {
        circleIntQueue.enqueue(price);
        return this;
    }

    /**
     * 计算五日均线.
     *
     * @return 五日均线的值
     */
    public float average() {
        return circleIntQueue.average();
    }
}
